package com.uk.reports;

import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;

import com.uk.data.entities.Fatura;
import com.vaadin.Application;
import com.vaadin.terminal.StreamResource;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

public class ReportWindow extends Window{

	
	
	public ReportWindow(Application app, JasperReportBuilder jasperReport) {
		super();
		this.center();
		this.setCaption("Pamja e raportit");
		this.setHeight("800px");
		this.setWidth("700px");
		
		this.addComponent(this.buildEmbedded(app, jasperReport));
		
		//app.addWindow(this);
		System.out.println("ReportWindow.ReportWindow()");
	}

	public ReportWindow(String caption, Application app, JasperReportBuilder jasperReport) {
		super(caption);
		this.buildEmbedded(app, jasperReport);
		app.addWindow(this);
	}
	
	
	private Embedded buildEmbedded(Application app, JasperReportBuilder jasperReport){
		
		
		StreamResource.StreamSource resstream = new FilePDF(jasperReport);
		StreamResource ress = new StreamResource(resstream, "jasperreport.pdf", app);
		ress.setMIMEType("application/pdf");
	    ress.setCacheTime(1);
	    
	    final Embedded embedded = new Embedded(null,ress);
	    embedded.setSource(ress);
	    embedded.setMimeType("application/pdf");
	    embedded.setType(Embedded.TYPE_BROWSER);
	    embedded.setSizeFull();
	    embedded.setHeight("900px");
	    embedded.setParameter("Content-Disposition", "attachment; filename=" + ress.getFilename());
		return embedded;
		
		
	}

}
